/**
 * zmn产品模块-产品列表
 * @author tanghongjun
 * @since 2018/10/18
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;


    // 分类下拉框联动
    zmnPage.laySelectLinkage(form, "/common/area/listChilds.action", "provinceId", "cityId", null);

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        defaultToolbar: ['filter'],
        height: 'full-189'
    });
    laypage.render(zmnPage.laypageOptions(json));

    var ids = new Array();
    // 【表格复选框监听】
    table.on("checkbox(zmn-table)", function () {
        ids = table.checkStatus('zmn-table').data.map((item) => item.channelPriceId);
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {
        if (obj.event == "start" || obj.event == "stop") {
            if (ids.length === 0) {
                return layer.alert("请选择至少一个要操作的记录！");
            }
            zmnPage.layStartStop(obj, "/pilot/channel/price/updateStatus.action", ids.join(","));
        }
    });

    $(".btn-operate").click(function () {
        let _this = $(this)
        let channelPriceId = _this.attr("dataId");
        let type = _this.attr("dataType");

        let html = "<div class='layui-btn-container'>" +
            "" + (json.hasEditView ? "<a lay-href='" + "/pilot/channel/price/addEditView.action?channelPriceId=" + channelPriceId + "' class='layui-btn layui-btn-sm layui-btn-normal' lay-text='编辑' style='width:75px'>编辑</a>" : '') +
            "" + (json.hasEditView ? "<a lay-href='" + "/pilot/channel/price/serviceCategory.action?type=1&showType=2&configId=" + channelPriceId + "' class='layui-btn layui-btn-sm layui-btn-normal' lay-text='应用分类' style='width:75px'>应用分类</a>" : '') +
            "" + (json.hasDetailView ? "<a lay-href='" + "/pilot/channel/price/detail.action?channelPriceId=" + channelPriceId + "' class='layui-btn layui-btn-sm layui-btn-normal' lay-text='详情' style='width:75px'>详情</a>" : '') +
            "" + (json.hasDel ? "<button onclick='deleteChannelConfig(" + channelPriceId + ")'  class='layui-btn layui-btn-sm layui-btn-normal' lay-text='删除' style='width:75px'>删除</button>" : '') +
            "</div>";
        indexTips = layer.tips(html, this, {
            shade: [0],
            shadeClose: true,
            area: ['370px', '50px'],
            time: 0,
            tips: [3, '#FFFFFF'],
        });

    });


//对外暴露的接口
    exports('channel_price_list_js', {});
});

// 根据id删除
function deleteChannelConfig(id) {
    layer.confirm("确认删除吗?", function (index) {
        layer.close(index);
        zmnLayUtil.ajaxSimpleUE("/pilot/channel/price/delete.action",
            {channelPriceId: id}, null, function (json) {
                layer.msg(json.message);
                if (json.status == 200) {
                    document.forms[0].submit();
                }
            });
    });
}